<extend name="Public/frame" />
<block name="content-box">

    <table id="table-grid" class="table table-hover">
        <thead>
        <tr>
            <foreach name="fields" item="v" key="k">
                <if condition="$v">
                    <if condition="strpos($v['rules'],'searchable')!==false">
                        <th data-column-id="{$k}" data-sortable="true">
                            {$v.title}
                        </th>
                    <else />
                        <th data-column-id="{$k}" data-sortable="false">
                            {$v.title}
                        </th>
                    </if>
                <else />
                    <th data-column-id="{$k}" data-order="desc" data-type="numeric" data-identifier="true">
                        {$k|strtoupper}
                    </th>
                </if>
            </foreach>
            <if condition="access_permit('cmshandle')">
            <th data-column-id="commands" data-formatter="commands" data-sortable="false">{$Think.lang.operation}</th>
            </if>
        </tr>
        </thead>
    </table>

    <script type="text/javascript">
        var grid;
        var grid_buttons = ['<div class="btn-group">',
            /*<if condition="access_permit('cmshandle')">*/
            /*<if condition="$cfg_addable">*/
            '<a href="javascript:void(0);" onclick="admin_grid_add(\'{:U(CONTROLLER_NAME.'/cmshandle?action=add&page=-page-')}\');" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></a>',
            /*</if>*/
            /*<if condition="$cfg_deletable">*/
            '<a href="javascript:void(0);" onclick="admin_grid_delete(\'{:U(CONTROLLER_NAME.'/cmshandle?action=delete&page=-page-')}\');" class="btn btn-default"><span class="glyphicon glyphicon-trash"></span></a>',
            /*</if>*/
            /*</if>*/
            '</div>'].join('');
        
        require(['jquery.bootgrid'],function(){
            grid = $("#table-grid").bootgrid({
                        <include file="Public:jstablelist" />
                        url: "{:U(CONTROLLER_NAME.'/cmslist')}",
                        formatters: {
                                commands: function(col, row){
                                    /*<if condition="!$cfg_all_field_readonly">*/
                                    return  "<a href='#' class='command-edit' title='{$Think.lang.edit}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-pencil'></span></a>"+
                                            "&nbsp;&nbsp;&nbsp;&nbsp;" +
                                            "<a href='#' class='command-delete' title='{$Think.lang.delete}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-remove'></span></a>";
                                    /*<else />*/
                                    return  "<a href='#' class='command-edit' title='{$Think.lang.edit}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-eye-open'></span></a>"+
                                            "&nbsp;&nbsp;&nbsp;&nbsp;" +
                                            "<a href='#' class='command-delete' title='{$Think.lang.delete}' data-row-id='" + row[this.identifier] + "'><span class='glyphicon glyphicon-remove'></span></a>";
                                    /*</if>*/
                                },
                        }
                    }).on("loaded.rs.jquery.bootgrid", function(){

                        grid.find(".command-edit").on("click", function(e){
                            admin_grid_edit('{:U(CONTROLLER_NAME.'/cmshandle?action=edit&id=-id-&page=-page-')}',$(this).data("row-id"));
                            return false;

                        }).end().find(".command-delete").on("click", function(e){

                            if(confirm('{$Think.lang.delete}?')){
                                admin_grid_delete_one( "{:U(CONTROLLER_NAME.'/cmshandle?action=delete')}", $(this).data("row-id"));
                            }
                            return false;

                        });
                });
        });

    </script>

</block>